home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1390 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: s02.pavilion.co.uk!usenet
  2. From: AJRobb@pavilion.co.uk (Andy J Robb)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: void pointers
  5. Date: Sat, 13 Jan 1996 15:32:15 GMT
  6. Organization: Pavilion Internet plc
  7. Message-ID: <4d8j83$n3@s02.pavilion.co.uk>
  8. References: <1996Jan12.133322.1@ccc.govt.nz>
  9. NNTP-Posting-Host: poolb34.pavilion.co.uk
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. mcauslanb@ccc.govt.nz wrote:
  13.  
  14. >I am writing a C program for an application that has a development language 
  15. >based on ANSI C.
  16.  
  17. >A function that I need to call is defined:
  18. >    void getFence (void **clipPP);
  19.  
  20. >   where "clipPP" is returned by the function.
  21.  
  22. >1) How do I declare and pass clipPP?
  23.  
  24. YourType *clipP;    /* set up an unitialized pointer */
  25. getFence(&clipP);    /* initialize it in the functions */
  26.  
  27. >2) What is actually going on?
  28.  
  29. The (void*) type is a dirty catch-all pointer.  It can point to
  30. anything but you must cast it or assign it to something else before
  31. you use it.
  32.  
  33. In my example, I have shown that I have a pointer to a type
  34. (YourType).  This allows the returned pointer to be used without
  35. casting.  I then passed the address OF this pointer (rather than the
  36. address held by the pointer) to the function, getFence().  The
  37. prototype declaration of getFence() will cause an implicit cast to
  38. (void**) in the call.  The function, getFence(), then does its
  39. business and returns the address of the result in the pointer, clipP.
  40. It can do this because you gave it the address of clipP.
  41.  
  42. Regards,
  43.  
  44. -----BEGIN PGP PUBLIC KEY BLOCK-----
  45. Version: 2.6.2i
  46.  
  47. mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
  48. MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
  49. B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
  50. tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
  51. IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
  52. =/wVD
  53. -----END PGP PUBLIC KEY BLOCK-----
  54.  
  55.